<template>
  <div>
    <p-form :form="form">
      <p-row>

        <p-col :span="12">
          <p-form-item label="产品编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <p-input v-decorator="[ 'procuctCode', validatorRules.procuctCode]" placeholder="请输入产品编码"></p-input>
          </p-form-item>
        </p-col>
        <p-col :span="12">
          <p-form-item label="产品名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <p-input v-decorator="[ 'productName', validatorRules.productName]" placeholder="请输入产品名称"></p-input>
          </p-form-item>
        </p-col>
        <p-col :span="12">
          <p-form-item label="创建者" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <p-input v-decorator="[ 'creator', validatorRules.creator]" placeholder="请输入创建者"></p-input>
          </p-form-item>
        </p-col>
        <p-col :span="12">
          <p-form-item label="修改者" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <p-input v-decorator="[ 'updator', validatorRules.updator]" placeholder="请输入修改者"></p-input>
          </p-form-item>
        </p-col>
        <p-col :span="12">
          <p-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <p-input v-decorator="[ 'notice', validatorRules.notice]" placeholder="请输入备注"></p-input>
          </p-form-item>
        </p-col>
        <p-col :span="12">
          <p-form-item label="质检管理文件id" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <p-input v-decorator="[ 'mesQualityFileManagementId', validatorRules.mesQualityFileManagementId]" placeholder="请输入质检管理文件id"></p-input>
          </p-form-item>
        </p-col>
      </p-row>
    </p-form>
  </div>
</template>
<script>
  import { SubmitOnchangMixin } from '@/mixins/SubmitOnchangMixin'
  import pick from 'lodash.pick'
  import { getAction } from '@/api/manage'

  export default {
    name: 'MesQualityFileProductDetailForm',
    mixins: [SubmitOnchangMixin],
    components: { 
    },
    data () {
      return {
        form: this.$form.createForm(this),
        model: {},
        labelCol: {
          span: 6
        },
        wrapperCol: {
          span: 16
        },
        labelCol2: {
          span: 3
        },
        wrapperCol2: {
          span: 20
        },
        confirmLoading: false,
        validatorRules:{
          procuctCode:{},
          productName:{},
          creator:{},
          updator:{},
          notice:{},
          mesQualityFileManagementId:{},
        },
        
      }
    },
    methods:{
      initFormData(url,id){
        this.clearFormData()
        if(!id){
          this.edit({})
        }else{
          getAction(url,{id:id}).then(res=>{
            if(res.success){
              let records = res.data
              if(records && records.length>0){
                this.edit(records[0])
              }
            }
          })
        }
      },
      edit(record){
        this.model = Object.assign({}, record)
        console.log("MesQualityFileProductDetailForm-edit",this.model);
        let fieldval = pick(this.model,'procuctCode','productName','creator','updator','notice','mesQualityFileManagementId')
        this.$nextTick(() => {
          this.form.setFieldsValue(fieldval)
        })
      },
      getFormData(){
        let formdata_arr = []
        this.form.validateFields((err, values) => {
          if (!err) {
            let formdata = Object.assign(this.model, values)
            let isNullObj = true
            Object.keys(formdata).forEach(key=>{
              if(formdata[key]){
                isNullObj = false
              }
            })
            if(!isNullObj){
              formdata_arr.push(formdata)
            }
          }else{
            this.$emit("validateError","产品/物料明细表单校验未通过");
          }
        })
        console.log("产品/物料明细表单数据集",formdata_arr);
        return formdata_arr;
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'procuctCode','productName','creator','updator','notice','mesQualityFileManagementId'))
      },
      clearFormData(){
        this.form.resetFields()
        this.model={}
      }
    
    }
  }
</script>
